import sys

import facade
from xjlibrary.our_file_dir import BaseDir

curPath = BaseDir.get_file_dir_absolute(__file__)
sys.path.append(curPath)

from base_sipo import BaseSipo

curPath = BaseDir.get_file_dir_absolute(__file__)
configfile = BaseDir.get_new_path(curPath, "db.ini")
jpgdir = BaseDir.get_new_path(curPath, "jpg")
BaseDir.create_dir(jpgdir)


class sipogovLogin(BaseSipo):

    def __init__(self):
        self.filelogger = facade.get_timerotatingfilelogger(BaseDir.get_new_path(curPath, "logs", "step1_check"))
        super().__init__(self.filelogger)
        self.configfile = configfile
        # self.localVal.sn = requests.session()
        # self.localVal.count = 0
        # self.cf = MyConfigParser(configfile).set_keep_keys_case().read_config()
        # self.userloginname = ""

    def get_proxy_ip_2(self):
        """
        获取米朴代理
        :return:
        """
        proxylist = ["82.194.235.142:8080", "39.137.107.98:80", "39.137.107.98:8080", "101.4.136.34:80",
                     "101.4.136.34:81",
                     "101.4.136.34:8080", "39.137.77.66:80", "39.137.77.66:8080", "159.138.20.247:80",
                     "119.28.203.242:8000",
                     "49.51.70.42:1080", "49.51.68.122:1080", "159.138.22.112:80", "159.138.21.170:80",
                     "82.194.235.162:8080",
                     "213.23.122.170:443", "200.255.122.170:8080", "13.56.2.56:8090", "200.255.122.174:8080",
                     "47.52.27.97:31280", "165.227.62.167:80", "68.183.53.127:8080", "134.209.123.111:8080",
                     "162.243.102.207:3128", "134.209.122.8:8080", "157.230.232.130:80", "111.206.6.101:80",
                     "134.209.123.111:8090", "159.138.3.119:80", "159.138.5.222:80", "159.138.1.185:80",
                     "45.55.46.222:8080",
                     "91.205.218.33:80", "198.11.178.14:8080", "47.94.230.42:9999", "118.24.182.249:8081",
                     "157.230.227.116:8080", "182.92.105.136:3128", "150.109.55.190:83", "124.202.166.171:82",
                     "157.230.232.130:8080", "157.230.227.116:80", "134.209.122.8:80", "213.23.122.170:83",
                     "65.52.174.40:80",
                     "117.191.11.75:8080", "117.191.11.105:80", "117.191.11.106:8080", "117.191.11.72:8080",
                     "117.191.11.107:8080", "117.191.11.103:8080", "117.191.11.102:80", "117.191.11.103:80",
                     "117.191.11.104:80",
                     "117.191.11.106:80", "117.191.11.104:8080", "117.191.11.75:80", "117.191.11.73:8080",
                     "117.191.11.74:8080",
                     "117.191.11.71:8080", "117.191.11.73:80", "117.191.11.72:80", "117.191.11.71:80",
                     "117.191.11.101:80",
                     "117.191.11.107:80", "117.191.11.74:80", "117.191.11.102:8080", "117.191.11.101:8080",
                     "117.191.11.105:8080", "138.197.162.114:8080", "157.230.57.151:8080", "157.230.210.133:8080",
                     "68.183.53.127:80", "157.230.157.60:8080", "104.248.115.226:8080", "157.230.163.11:80",
                     "157.230.149.189:80", "157.230.140.12:8080", "159.65.236.197:8080", "222.110.147.50:3128",
                     "101.251.215.232:8081", "142.93.202.126:8080", "157.230.163.11:8080", "104.248.123.136:8080",
                     "68.183.99.96:8080", "198.199.122.218:8080", "157.230.210.133:80", "120.210.219.105:80",
                     "120.210.219.104:80", "120.210.219.101:80", "120.210.219.102:80", "120.210.219.101:8080",
                     "91.205.218.32:80", "35.235.75.244:3128"]

        listvalues = []
        for proxyobj in proxylist:
            proxy = proxyobj
            ip = proxy.split(":")[0]
            interval = 0
            listvalues.append((ip, proxy, int(interval)))
        if listvalues:
            sql = "replace into `proxy_pool`(`ipaddr`,`proxy`,`stat`,`source`,`interval`) values(%s,%s,0,'other',%s)"
            self.mysqlutils.ExeSqlMany(sql, listvalues)

    import facade

    def check_proxy_post(self, proxys=None):
        url = "http://httpbin.org/post"
        values = {'a': '1', 'b': '2'}
        BoolResult, errString, r = facade.BaseRequestPost(url,
                                                          data=values,
                                                          endstring="",
                                                          timeout=30)
        if BoolResult:
            print(r.text)
            return True
        else:
            return False



if __name__ == "__main__":
    sets = sipogovLogin()
    # sets.get_proxy_ip_2()
